package com.token.sysflow.core;
import com.alibaba.fastjson.JSONArray;
import com.token.sql.IntegrateSql;
import com.token.sysflow.exception.ErrorCodeEnum;
import com.token.sysflow.exception.FlowException;
import com.token.sysflow.hander.ApproveProcess;
import com.token.sysflow.impl.AbstractFlowHandlerImpl;
import lombok.Getter;


/**
 * 读取退回环节
 * @author chenjianxiong 2020/4/13
 */
public class ReturnPathApprover extends AbstractFlowCore {
    @Getter
    private final JSONArray jsonArray;
    public ReturnPathApprover(IntegrateSql f, String keyUnid) throws Exception {
        super(f, keyUnid);
        jsonArray = new JSONArray();
    }

    /**
     * 执行
     * @param flowHandler
     * @throws Exception
     */
    public void execute(AbstractFlowHandlerImpl flowHandler) throws Exception{

        //检查流程状态，结束和终止不允许操作
        checkFlowStatus();

        //判断当前用户是否是当前办理人
        if (!approveProcess.isStepApproves(flowHandler.getActionUser(), ApproveProcess.STATUS_IND)) {
            throw new FlowException(ErrorCodeEnum.CHECK_APPROVE,flowHandler.getActionUser());
        }

        //输出历史审批环节
        flowRecord.disFlowRecord(jsonArray);
    }

}
